import { IPSAppCounterRef } from '../../app/control/ipsapp-counter-ref';
import { IPSAppView } from '../../app/view/ipsapp-view';
import { IPSAppViewUIAction } from '../../app/view/ipsapp-view-uiaction';
import { IPSNavigateContext } from '../ipsnavigate-context';
import { IPSNavigateParam } from '../ipsnavigate-param';
import { IPSDEForm } from './ipsdeform';
import { IPSDEFormButton } from './ipsdeform-button';
import { IPSDEFormItemUpdate } from './ipsdeform-item-update';
import { PSDEFormDetailImpl } from './psdeform-detail-impl';
import { IPSUIAction } from '../../view/ipsuiaction';

export class PSDEFormButtonImpl extends PSDEFormDetailImpl implements IPSDEFormButton {
  get actionType(): 'UIACTION' | 'FIUPDATE' {
    return this.M.actionType;
  }

  get captionItemName(): string {
    return this.M.captionItemName;
  }

  protected psappcounterref: IPSAppCounterRef | null = null;

  getPSAppCounterRef(): IPSAppCounterRef | null {
    if (this.psappcounterref != null) return this.psappcounterref;
    const value = this.M.getPSAppCounterRef;
    if (value == null) {
      return null;
    }
    this.psappcounterref = this.getPSModel4('app.control.IPSAppCounterRef', value, 'getPSAppCounterRef') as IPSAppCounterRef;
    return this.psappcounterref;
  }

  get psAppCounterRef(): IPSAppCounterRef | null {
    return this.getPSAppCounterRef();
  }

  getPSAppCounterRefMust(): IPSAppCounterRef {
    const value = this.getPSAppCounterRef();
    if (value == null) {
      throw new Error('未指定应用计数器引用');
    }
    return value;
  }

  protected psappviewuiaction: IPSAppViewUIAction | null = null;

  getPSAppViewUIAction(): IPSAppViewUIAction | null {
    if (this.psappviewuiaction != null) return this.psappviewuiaction;
    const value = this.M.getPSAppViewUIAction;
    if (value == null) {
      return null;
    }
    this.psappviewuiaction = this.getPSModel4('app.view.IPSAppViewUIAction', value, 'getPSAppViewUIAction') as IPSAppViewUIAction;
    return this.psappviewuiaction;
  }

  get psAppViewUIAction(): IPSAppViewUIAction | null {
    return this.getPSAppViewUIAction();
  }

  getPSAppViewUIActionMust(): IPSAppViewUIAction {
    const value = this.getPSAppViewUIAction();
    if (value == null) {
      throw new Error('未指定应用视图界面行为');
    }
    return value;
  }

  protected psdeformitemupdate: IPSDEFormItemUpdate | null = null;

  getPSDEFormItemUpdate(): IPSDEFormItemUpdate | null {
    if (this.psdeformitemupdate != null) return this.psdeformitemupdate;
    const value = this.M.getPSDEFormItemUpdate;
    if (value == null) {
      return null;
    }
    const ipsdeform = this.getParentPSModelObject('control.form.IPSDEForm') as IPSDEForm;
    if (ipsdeform != null) {
      this.psdeformitemupdate = ipsdeform.findPSDEFormItemUpdate(value);
    }
    return this.psdeformitemupdate;
  }

  get psDEFormItemUpdate(): IPSDEFormItemUpdate | null {
    return this.getPSDEFormItemUpdate();
  }

  getPSDEFormItemUpdateMust(): IPSDEFormItemUpdate {
    const value = this.getPSDEFormItemUpdate();
    if (value == null) {
      throw new Error('未指定调用表单项更新');
    }
    return value;
  }

  protected psnavigatecontexts: IPSNavigateContext[] | null = null;

  getPSNavigateContexts(): IPSNavigateContext[] | null {
    if (this.psnavigatecontexts == null) {
      this.psnavigatecontexts = this.fillChildListModel(this.M.getPSNavigateContexts, 'control.IPSNavigateContext') as IPSNavigateContext[];
    }
    return this.psnavigatecontexts;
  }

  get psNavigateContexts(): IPSNavigateContext[] | null {
    return this.getPSNavigateContexts();
  }

  findPSNavigateContext(objKey: any): IPSNavigateContext | null {
    return this.getPSModel5('control.IPSNavigateContext', this.getPSNavigateContexts(), objKey) as IPSNavigateContext;
  }

  protected psnavigateparams: IPSNavigateParam[] | null = null;

  getPSNavigateParams(): IPSNavigateParam[] | null {
    if (this.psnavigateparams == null) {
      this.psnavigateparams = this.fillChildListModel(this.M.getPSNavigateParams, 'control.IPSNavigateParam') as IPSNavigateParam[];
    }
    return this.psnavigateparams;
  }

  get psNavigateParams(): IPSNavigateParam[] | null {
    return this.getPSNavigateParams();
  }

  findPSNavigateParam(objKey: any): IPSNavigateParam | null {
    return this.getPSModel5('control.IPSNavigateParam', this.getPSNavigateParams(), objKey) as IPSNavigateParam;
  }

  protected psuiaction: IPSUIAction | null = null;

  getPSUIAction(): IPSUIAction | null {
    if (this.psuiaction != null) return this.psuiaction;
    const value = this.M.getPSUIAction;
    if (value == null) {
      return null;
    }
    this.psuiaction = this.getPSModel4('view.IPSUIAction', value, 'getPSUIAction') as IPSUIAction;
    return this.psuiaction;
  }

  get psUIAction(): IPSUIAction | null {
    return this.getPSUIAction();
  }

  getPSUIActionMust(): IPSUIAction {
    const value = this.getPSUIAction();
    if (value == null) {
      throw new Error('未指定调用界面行为');
    }
    return value;
  }

  protected parampickuppsappview: IPSAppView | null = null;

  getParamPickupPSAppView(): IPSAppView | null {
    if (this.parampickuppsappview != null) return this.parampickuppsappview;
    const value = this.M.getParamPickupPSAppView;
    if (value == null) {
      return null;
    }
    this.parampickuppsappview = this.getPSModel4('app.view.IPSAppView', value, 'getParamPickupPSAppView') as IPSAppView;
    return this.parampickuppsappview;
  }

  get paramPickupPSAppView(): IPSAppView | null {
    return this.getParamPickupPSAppView();
  }

  getParamPickupPSAppViewMust(): IPSAppView {
    const value = this.getParamPickupPSAppView();
    if (value == null) {
      throw new Error('未指定参数选择视图');
    }
    return value;
  }

  get paramViewParamJO(): IModel {
    return this.M.paramViewParamJO;
  }

  get tooltip(): string {
    return this.M.tooltip;
  }

  get uIActionParamJO(): IModel {
    return this.M.uIActionParamJO;
  }

  get uIActionTarget(): 'SINGLEDATA' | 'SINGLEKEY' | 'MULTIDATA' | 'MULTIKEY' | 'NONE' {
    return this.M.uIActionTarget;
  }

  get xDataControlName(): string {
    return this.M.xDataControlName;
  }

  get saveTargetFirst(): boolean {
    return this.M.saveTargetFirst != null ? this.M.saveTargetFirst : false;
  }

  get cls(): string {
    return 'PSDEFormButtonImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'app.view.IPSAppViewUIAction' || cls == 'app.view.IPSUIActionItem' || cls == 'control.IPSNavigateParamContainer' || cls == 'control.form.IPSDEFormButton') return true;
    return super.instanceof(cls);
  }
}
